/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import utility.ImageToolbox;

/**
 *
 * @author Jeppe
 */
public class IndstillingerDialog extends javax.swing.JDialog {

    private MainGui mainGui;
    private FilVælger filVælger;
    private ImageToolbox imgTB;

    /**
     * Creates new form Indstillinger
     */
    public IndstillingerDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        mainGui = (MainGui) parent;
        filVælger = new FilVælger(parent, modal);
        imgTB = new ImageToolbox();
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        baggrund = new javax.swing.ButtonGroup();
        deckTypeGroup = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jRadioButton2 = new javax.swing.JRadioButton();
        standardBaggrundLabel = new javax.swing.JLabel();
        vælgBaggrundKnap = new javax.swing.JButton();
        baggrundFilStiTxt = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        klassiskDeckRadio = new javax.swing.JRadioButton();
        moderneDeckRadio = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel(){
            public void paint (Graphics g){
                super.paint(g);
                imgTB.drawImage(g, (ImageIcon)jLabel2.getIcon(), 0, 0,jLabel2.getSize().width, jLabel2.getSize().height);
            }
        }
        ;
        jLabel4 = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setAlwaysOnTop(true);

        baggrund.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Standard");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Baggrund");

        baggrund.add(jRadioButton2);
        jRadioButton2.setText("Brugerdefineret");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        standardBaggrundLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/baggrund.jpg"))); // NOI18N

        vælgBaggrundKnap.setText("Vælg Baggrund");
        vælgBaggrundKnap.setEnabled(false);
        vælgBaggrundKnap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                vælgBaggrundKnapActionPerformed(evt);
            }
        });

        baggrundFilStiTxt.setEditable(false);
        baggrundFilStiTxt.setText("C://");
        baggrundFilStiTxt.setEnabled(false);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText("Deck");

        deckTypeGroup.add(klassiskDeckRadio);
        klassiskDeckRadio.setText("Klassisk");

        deckTypeGroup.add(moderneDeckRadio);
        moderneDeckRadio.setSelected(true);
        moderneDeckRadio.setText("Moderne");
        moderneDeckRadio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moderneDeckRadioActionPerformed(evt);
            }
        });

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/klassiskekort/Blue_Back.png"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/DeckKort.PNG"))); // NOI18N

        saveButton.setText("Gem");
        saveButton.setEnabled(false);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel1))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jRadioButton1)
                .addGap(38, 38, 38)
                .addComponent(standardBaggrundLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jRadioButton2)
                .addGap(6, 6, 6)
                .addComponent(baggrundFilStiTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(vælgBaggrundKnap))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel3)
                .addGap(15, 15, 15)
                .addComponent(klassiskDeckRadio)
                .addGap(71, 71, 71)
                .addComponent(moderneDeckRadio, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(350, 350, 350)
                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jRadioButton1))
                    .addComponent(standardBaggrundLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton2)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(baggrundFilStiTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(vælgBaggrundKnap))
                .addGap(6, 6, 6)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel3))
                    .addComponent(klassiskDeckRadio)
                    .addComponent(moderneDeckRadio))
                .addGap(3, 3, 3)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addComponent(saveButton))
        );

        jTabbedPane1.addTab("Udseende", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        if (klassiskDeckRadio.isSelected()) {
            mainGui.setDeckIcon((ImageIcon) jLabel2.getIcon());
        } else {
            mainGui.setDeckIcon((ImageIcon) jLabel4.getIcon());
        }
        if (jRadioButton1.isSelected()) {
            mainGui.setBackGround((ImageIcon) standardBaggrundLabel.getIcon());
        } else {
            mainGui.setBackGround(new ImageIcon(baggrundFilStiTxt.getText()));
        }
        saveButton.setEnabled(false);
    }//GEN-LAST:event_saveButtonActionPerformed

    private void moderneDeckRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moderneDeckRadioActionPerformed
        saveButton.setEnabled(true);
    }//GEN-LAST:event_moderneDeckRadioActionPerformed

    private void vælgBaggrundKnapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_vælgBaggrundKnapActionPerformed
        //filVælger.setVisible(true);
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileFilter(new FileNameExtensionFilter("PNG (*.png)", "png"));
        fileChooser.showOpenDialog(this);
        baggrundFilStiTxt.setText(fileChooser.getSelectedFile().getPath());
        saveButton.setEnabled(true);
    }//GEN-LAST:event_vælgBaggrundKnapActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        baggrundFilStiTxt.setEnabled(true);
        vælgBaggrundKnap.setEnabled(true);
        standardBaggrundLabel.setEnabled(false);
        saveButton.setEnabled(true);
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        baggrundFilStiTxt.setEnabled(false);
        vælgBaggrundKnap.setEnabled(false);
        standardBaggrundLabel.setEnabled(true);
        saveButton.setEnabled(true);
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(IndstillingerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(IndstillingerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(IndstillingerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(IndstillingerDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                IndstillingerDialog dialog = new IndstillingerDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup baggrund;
    private javax.swing.JTextField baggrundFilStiTxt;
    private javax.swing.ButtonGroup deckTypeGroup;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JRadioButton klassiskDeckRadio;
    private javax.swing.JRadioButton moderneDeckRadio;
    private javax.swing.JButton saveButton;
    private javax.swing.JLabel standardBaggrundLabel;
    private javax.swing.JButton vælgBaggrundKnap;
    // End of variables declaration//GEN-END:variables
}
